<?

class holiday_filters {



// Function // Find a holiday that has a modified price or is to be hidden
function find_holiday_mod_price($holiday_reference_id,$type=false){

	if(!empty($holiday_reference_id)){
		
		$params = in($holiday_reference_id);
	
		$sql = "SELECT mod_price, entry_date, mod_price_a
		FROM holiday_price_filter
		WHERE holiday_reference_id = '".trim($holiday_reference_id)."'
		LIMIT 1 ";
		
		$result = apply_query($sql);
	
	}
	
	if($result){
	
		if($type=='prepared'){
			
			$mod_price_s = @json_decode($result[0]['mod_price_a'],true);
	
			if($mod_price_s){
				if($mod_price_s['price_adult']) $effective_price_adult = $mod_price_s['price_adult'];
				if($mod_price_s['price_child']) $effective_price_child = $mod_price_s['price_child'];
			}else{
				$effective_price_adult = $mod_price[0]['mod_price'];
			}
			
			$prepared_array = array(
									'entry_date'=>$result[0]['entry_date'],
									'mod_price'=>$result[0]['mod_price'],
									'price_adult'=>$effective_price_adult,
									'price_child'=>$effective_price_child
									);
			
			return $prepared_array;
			
		}
	
	}else{
		
		return false;
		
	}
	

}


// Function // Find a holiday thats hidden
function find_filtered_holiday($holiday_reference_id){

	if(!empty($holiday_reference_id)){

		$params = in($holiday_reference_id);
	
		$sql = "SELECT holiday_reference_id
		FROM holiday_holiday_filter
		WHERE holiday_reference_id = '".$holiday_reference_id."'
		LIMIT 1 ";
		
		return apply_query($sql);

	}
}


// Function // Find a flight thats hidden
function find_filtered_flight($params){

	
	if(!empty($params)){

		$params = in($params);
	
		$sql = "SELECT tour_op
		FROM holiday_flight_filter
		WHERE tour_op = '".$params['tour_op']."'
		AND destination_airport = '".$params['destination_airport']."'
		AND departure_airport = '".$params['departure_airport']."'
		AND departure_date = '".$params['departure_date']."'
		AND return_date = '".$params['return_date']."'
		AND depart_dept_time = '".$params['depart_dept_time']."'
		AND arrive_dept_time = '".$params['arrive_dept_time']."'
		AND depart_dest_time = '".$params['depart_dest_time']."'
		AND arrive_dest_time = '".$params['arrive_dest_time']."'
		AND nights = '".$params['nights']."'
		LIMIT 1 ";

		return apply_query($sql);
		
	}
	
}



// FUNCTION // Insert mod price 
function insert_holiday_mod_price($params){

if(!empty($params)){
	
	$params = in($params);

	$sql = "INSERT INTO holiday_price_filter
	SET	holiday_reference_id = '".$params['holiday_reference_id']."',
	mod_price_a = '".$params['mod_price']."',
	entry_date = '".mktime()."' ";
	
	$result = mysql_query($sql) or die (mysql_error());
	
	return mysql_insert_id();
	
}


}
// FUNCTION // Update mod price
function update_holiday_mod_price($params){
	
if(!empty($params)){

	$params = in($params);

	$sql = "UPDATE holiday_price_filter
	SET	mod_price_a = '".$params['mod_price']."',
	entry_date = '".mktime()."'
	WHERE holiday_reference_id = '".$params['holiday_reference_id']."' ";
	
	$result = mysql_query($sql) or die (mysql_error());

}

}


// Function // Insert filtered holiday
function insert_filtered_holiday($reference_id){

	if(!empty($reference_id)){
		
		$params = in($params);
	
		$sql = "INSERT INTO holiday_holiday_filter
		SET holiday_reference_id = '".$reference_id."',
		entry_date = '".mktime()."' ";
	
		$result = mysql_query($sql) or die (mysql_error());
		
		return mysql_insert_id();
	
	}

}




// Function // Insert filtered flight
function insert_filtered_flight($params){

	$params = in($params);

	$sql = "INSERT INTO holiday_flight_filter
	SET tour_op = '".$params['tour_op']."',
	destination_airport = '".$params['destination_airport']."',
	departure_airport = '".$params['departure_airport']."',
	departure_date = '".$params['departure_date']."',
	return_date = '".$params['return_date']."',
	depart_dept_time = '".$params['depart_dept_time']."',
	arrive_dept_time = '".$params['arrive_dept_time']."',
	depart_dest_time = '".$params['depart_dest_time']."',
	arrive_dest_time = '".$params['arrive_dest_time']."',
	nights = '".$params['nights']."',
	entry_date = '".mktime()."' ";

	$result = mysql_query($sql) or die (mysql_error());
	
	return mysql_insert_id();

}


// FUNCTION // Delete item
function delete_hidden_holiday($holiday_filter_id){


	$sql = "DELETE FROM holiday_holiday_filter
	WHERE holiday_filter_id = '".$holiday_filter_id."
	LIMIT 1 ";
	
	$result = mysql_query($sql) or die (mysql_error());
	
	return mysql_insert_id();


}











}
?>